﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using MOCSoftware.Utilities.JpgMetaDataViewer.Annotations;

namespace MOCSoftware.Utilities.JpgMetaDataViewer.Viewmodel
{
    internal abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }

        internal void VerifyPropertyName(string propertyName)
        {
            if (string.IsNullOrWhiteSpace(propertyName))
                return;

            if (TypeDescriptor.GetProperties(this)[propertyName] == null)
            {
                throw new Exception("Invalid property name: " + propertyName);
            }
        }

        protected void OnViewCommand(EventHandler handler)
        {
            if (handler != null)
                handler(this, EventArgs.Empty);
        }

        internal abstract void Initialise();
    }
}
